package com.wc.codeforces.模拟.Mathematical_Problem;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/7/18 9:30
 * @description https://codeforces.com/problemset/problem/1986/D
 */
public class Main {
    /**
     * 思路：暴力枚举连接点, 其他的大于2的是可以相加的, 等于1的直接相乘最好
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 25, INF = (int)1e9;
    static char[] s = new char[N];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
//        int T = 1;
        while (T-- > 0) {
            n = sc.nextInt();
            s = (" " + sc.next()).toCharArray();
            int res = INF;
            if (n == 2) {
                res = (s[1] - '0') * 10 + s[2] - '0';
            } else if (n == 3 && (s[1] == '0' || s[n] == '0')) {
                res = 0;
            } else if (n == 3) {
                int a = s[1] - '0', b = s[2] - '0', c = s[3] - '0';
                res = Math.min(Math.min(a * 10 + b + c, a + b * 10 + c), Math.min((a * 10 + b) * c, a * (b * 10 + c)));
            } else if (n > 3) {
                // 枚举连接点
                for (int i = 1; i < n; i++) {
                    if (s[i] == '0' || s[n] == '0') {
                        res = 0;
                        break;
                    }

                    int curRes = 0,last = 0;
                    for (int j = 1; j <= n; j++) {
                        int c = s[j] - '0';
                        // 这个值被连接了
                        if (j == i + 1) continue;
                        if (j == i) {
                            c = c * 10 + s[j + 1] - '0';
                        }
                        if (c == 1) continue;
                        curRes += last;
                        last = c;
                    }
                    curRes += last;
                    res = Math.min(res, curRes);
                }
            }
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
